/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using Amazon.ECS;
using Amazon.ECS.Model;

namespace Amazon.ECS.Samples
{

    /// <summary>
    /// Cart Modify  Samples
    /// </summary>
    public class CartModifySample
    {
    
                                                                             
        /// <summary>
        /// 
        /// <p/>
        /// The CartModify operation enables you to:
        /// <p/>
        /// <ul>
        /// <li>Change the quantity of items that are already in a remote shopping cart.</li>
        /// <li>Move items from the active area of a cart to the SaveForLater area or the reverse</li>
        /// <li>Change the MergeCart setting. </li>
        /// </ul>
        /// <p/>
        /// To modify the number of items in a cart, you must specify the
        /// cart using the CartId and HMAC values that are returned in the
        /// CartCreate operation. A value similar to HMAC, URLEncodedHMAC,
        /// is also returned. This value is the URL encoded version of the HMAC.
        /// This encoding is necessary because some characters, such as + and /,
        /// cannot be included in a URL. Rather than encoding the HMAC yourself,
        /// use the URLEncodedHMAC value for the HMAC parameter.
        /// <p/>
        /// You can use CartModify to modify the number of items in a remote shopping
        /// cart by setting the value of the Quantity parameter appropriately. You can
        /// eliminate an item from a cart by setting the value of the Quantity parameter
        /// to zero. Or, you can double the number of a particular item in the cart by
        /// doubling its Quantity . You cannot, however, use CartModify to add new items to a cart.
        /// <p/>
        /// If the associated CartCreate request specified an AssociateTag, all
        /// CartModify requests must also include a value for Associate Tag
        /// otherwise the request will fail.
        /// <p/>
        /// <b>Available Response Groups</b>:
        /// <ul>
        /// <li>Request</li>
        /// <li>Cart</li>
        /// <li>CartSimilarities</li>
        /// <li>CartTopSellers</li>
        /// <li>CartNewReleases</li>
        /// </ul>
        /// 
        /// </summary>
        /// <param name="service">Instance of AmazonECS service</param>
        /// <param name="request">CartModify request</param>
        public static void InvokeCartModify(AmazonECS service, params CartModifyRequest [] request) 
        {
            try 
            {
                CartModifyResponse response = service.CartModify(request);
                
                
                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        CartModifyResponse");
                if (response.IsSetOperationRequest()) 
                {
                    Console.WriteLine("            OperationRequest");
                    OperationRequest  operationRequest = response.OperationRequest;
                    if (operationRequest.IsSetHTTPHeaders()) 
                    {
                        Console.WriteLine("                HTTPHeaders");
                        HTTPHeaders  HTTPHeaders = operationRequest.HTTPHeaders;
                    } 
                    if (operationRequest.IsSetRequestId()) 
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", operationRequest.RequestId);
                    }
                    if (operationRequest.IsSetArguments()) 
                    {
                        Console.WriteLine("                Arguments");
                        Arguments  arguments = operationRequest.Arguments;
                    } 
                    if (operationRequest.IsSetRequestProcessingTime()) 
                    {
                        Console.WriteLine("                RequestProcessingTime");
                        Console.WriteLine("                    {0}", operationRequest.RequestProcessingTime);
                    }
                } 
                List<Cart> cartList = response.Cart;
                foreach (Cart cart in cartList) 
                {
                    Console.WriteLine("            Cart");
                    if (cart.IsSetCartId()) 
                    {
                        Console.WriteLine("                CartId");
                        Console.WriteLine("                    {0}", cart.CartId);
                    }
                    if (cart.IsSetHMAC()) 
                    {
                        Console.WriteLine("                HMAC");
                        Console.WriteLine("                    {0}", cart.HMAC);
                    }
                    if (cart.IsSetURLEncodedHMAC()) 
                    {
                        Console.WriteLine("                URLEncodedHMAC");
                        Console.WriteLine("                    {0}", cart.URLEncodedHMAC);
                    }
                    if (cart.IsSetPurchaseURL()) 
                    {
                        Console.WriteLine("                PurchaseURL");
                        Console.WriteLine("                    {0}", cart.PurchaseURL);
                    }
                    if (cart.IsSetSubTotal()) 
                    {
                        Console.WriteLine("                SubTotal");
                        Price  subTotal = cart.SubTotal;
                        if (subTotal.IsSetAmount()) 
                        {
                            Console.WriteLine("                    Amount");
                            Console.WriteLine("                        {0}", subTotal.Amount);
                        }
                        if (subTotal.IsSetCurrencyCode()) 
                        {
                            Console.WriteLine("                    CurrencyCode");
                            Console.WriteLine("                        {0}", subTotal.CurrencyCode);
                        }
                        if (subTotal.IsSetFormattedPrice()) 
                        {
                            Console.WriteLine("                    FormattedPrice");
                            Console.WriteLine("                        {0}", subTotal.FormattedPrice);
                        }
                    } 
                    if (cart.IsSetCartItems()) 
                    {
                        Console.WriteLine("                CartItems");
                        CartItems  cartItems = cart.CartItems;
                        if (cartItems.IsSetSubTotal()) 
                        {
                            Console.WriteLine("                    SubTotal");
                            Price  subTotal = cartItems.SubTotal;
                            if (subTotal.IsSetAmount()) 
                            {
                                Console.WriteLine("                        Amount");
                                Console.WriteLine("                            {0}", subTotal.Amount);
                            }
                            if (subTotal.IsSetCurrencyCode()) 
                            {
                                Console.WriteLine("                        CurrencyCode");
                                Console.WriteLine("                            {0}", subTotal.CurrencyCode);
                            }
                            if (subTotal.IsSetFormattedPrice()) 
                            {
                                Console.WriteLine("                        FormattedPrice");
                                Console.WriteLine("                            {0}", subTotal.FormattedPrice);
                            }
                        } 
                        List<CartItem> cartItemList = cartItems.CartItem;
                        foreach (CartItem cartItem in cartItemList) 
                        {
                            Console.WriteLine("                    CartItem");
                            if (cartItem.IsSetCartItemId()) 
                            {
                                Console.WriteLine("                        CartItemId");
                                Console.WriteLine("                            {0}", cartItem.CartItemId);
                            }
                            if (cartItem.IsSetASIN()) 
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", cartItem.ASIN);
                            }
                            if (cartItem.IsSetExchangeId()) 
                            {
                                Console.WriteLine("                        ExchangeId");
                                Console.WriteLine("                            {0}", cartItem.ExchangeId);
                            }
                            if (cartItem.IsSetMerchantId()) 
                            {
                                Console.WriteLine("                        MerchantId");
                                Console.WriteLine("                            {0}", cartItem.MerchantId);
                            }
                            if (cartItem.IsSetSellerId()) 
                            {
                                Console.WriteLine("                        SellerId");
                                Console.WriteLine("                            {0}", cartItem.SellerId);
                            }
                            if (cartItem.IsSetSellerNickname()) 
                            {
                                Console.WriteLine("                        SellerNickname");
                                Console.WriteLine("                            {0}", cartItem.SellerNickname);
                            }
                            if (cartItem.IsSetQuantity()) 
                            {
                                Console.WriteLine("                        Quantity");
                                Console.WriteLine("                            {0}", cartItem.Quantity);
                            }
                            if (cartItem.IsSetTitle()) 
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", cartItem.Title);
                            }
                            if (cartItem.IsSetProductGroup()) 
                            {
                                Console.WriteLine("                        ProductGroup");
                                Console.WriteLine("                            {0}", cartItem.ProductGroup);
                            }
                            if (cartItem.IsSetListOwner()) 
                            {
                                Console.WriteLine("                        ListOwner");
                                Console.WriteLine("                            {0}", cartItem.ListOwner);
                            }
                            if (cartItem.IsSetListType()) 
                            {
                                Console.WriteLine("                        ListType");
                                Console.WriteLine("                            {0}", cartItem.ListType);
                            }
                            if (cartItem.IsSetMetaData()) 
                            {
                                Console.WriteLine("                        MetaData");
                                CartItemMetaData  metaData = cartItem.MetaData;
                                List<MetaData> keyValuePairList = metaData.KeyValuePair;
                                foreach (MetaData keyValuePair in keyValuePairList) 
                                {
                                    Console.WriteLine("                            KeyValuePair");
                                    if (keyValuePair.IsSetKey()) 
                                    {
                                        Console.WriteLine("                                Key");
                                        Console.WriteLine("                                    {0}", keyValuePair.Key);
                                    }
                                    if (keyValuePair.IsSetValue()) 
                                    {
                                        Console.WriteLine("                                Value");
                                        Console.WriteLine("                                    {0}", keyValuePair.Value);
                                    }
                                }
                            } 
                            if (cartItem.IsSetPrice()) 
                            {
                                Console.WriteLine("                        Price");
                                Price  price = cartItem.Price;
                                if (price.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", price.Amount);
                                }
                                if (price.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", price.CurrencyCode);
                                }
                                if (price.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", price.FormattedPrice);
                                }
                            } 
                            if (cartItem.IsSetItemTotal()) 
                            {
                                Console.WriteLine("                        ItemTotal");
                                Price  itemTotal = cartItem.ItemTotal;
                                if (itemTotal.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", itemTotal.Amount);
                                }
                                if (itemTotal.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", itemTotal.CurrencyCode);
                                }
                                if (itemTotal.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", itemTotal.FormattedPrice);
                                }
                            } 
                        }
                    } 
                    if (cart.IsSetSavedForLaterItems()) 
                    {
                        Console.WriteLine("                SavedForLaterItems");
                        SavedForLaterItems  savedForLaterItems = cart.SavedForLaterItems;
                        if (savedForLaterItems.IsSetSubTotal()) 
                        {
                            Console.WriteLine("                    SubTotal");
                            Price  subTotal = savedForLaterItems.SubTotal;
                            if (subTotal.IsSetAmount()) 
                            {
                                Console.WriteLine("                        Amount");
                                Console.WriteLine("                            {0}", subTotal.Amount);
                            }
                            if (subTotal.IsSetCurrencyCode()) 
                            {
                                Console.WriteLine("                        CurrencyCode");
                                Console.WriteLine("                            {0}", subTotal.CurrencyCode);
                            }
                            if (subTotal.IsSetFormattedPrice()) 
                            {
                                Console.WriteLine("                        FormattedPrice");
                                Console.WriteLine("                            {0}", subTotal.FormattedPrice);
                            }
                        } 
                        List<CartItem> savedForLaterItemList = savedForLaterItems.SavedForLaterItem;
                        foreach (CartItem savedForLaterItem in savedForLaterItemList) 
                        {
                            Console.WriteLine("                    SavedForLaterItem");
                            if (savedForLaterItem.IsSetCartItemId()) 
                            {
                                Console.WriteLine("                        CartItemId");
                                Console.WriteLine("                            {0}", savedForLaterItem.CartItemId);
                            }
                            if (savedForLaterItem.IsSetASIN()) 
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", savedForLaterItem.ASIN);
                            }
                            if (savedForLaterItem.IsSetExchangeId()) 
                            {
                                Console.WriteLine("                        ExchangeId");
                                Console.WriteLine("                            {0}", savedForLaterItem.ExchangeId);
                            }
                            if (savedForLaterItem.IsSetMerchantId()) 
                            {
                                Console.WriteLine("                        MerchantId");
                                Console.WriteLine("                            {0}", savedForLaterItem.MerchantId);
                            }
                            if (savedForLaterItem.IsSetSellerId()) 
                            {
                                Console.WriteLine("                        SellerId");
                                Console.WriteLine("                            {0}", savedForLaterItem.SellerId);
                            }
                            if (savedForLaterItem.IsSetSellerNickname()) 
                            {
                                Console.WriteLine("                        SellerNickname");
                                Console.WriteLine("                            {0}", savedForLaterItem.SellerNickname);
                            }
                            if (savedForLaterItem.IsSetQuantity()) 
                            {
                                Console.WriteLine("                        Quantity");
                                Console.WriteLine("                            {0}", savedForLaterItem.Quantity);
                            }
                            if (savedForLaterItem.IsSetTitle()) 
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", savedForLaterItem.Title);
                            }
                            if (savedForLaterItem.IsSetProductGroup()) 
                            {
                                Console.WriteLine("                        ProductGroup");
                                Console.WriteLine("                            {0}", savedForLaterItem.ProductGroup);
                            }
                            if (savedForLaterItem.IsSetListOwner()) 
                            {
                                Console.WriteLine("                        ListOwner");
                                Console.WriteLine("                            {0}", savedForLaterItem.ListOwner);
                            }
                            if (savedForLaterItem.IsSetListType()) 
                            {
                                Console.WriteLine("                        ListType");
                                Console.WriteLine("                            {0}", savedForLaterItem.ListType);
                            }
                            if (savedForLaterItem.IsSetMetaData()) 
                            {
                                Console.WriteLine("                        MetaData");
                                CartItemMetaData  metaData = savedForLaterItem.MetaData;
                                List<MetaData> keyValuePairList = metaData.KeyValuePair;
                                foreach (MetaData keyValuePair in keyValuePairList) 
                                {
                                    Console.WriteLine("                            KeyValuePair");
                                    if (keyValuePair.IsSetKey()) 
                                    {
                                        Console.WriteLine("                                Key");
                                        Console.WriteLine("                                    {0}", keyValuePair.Key);
                                    }
                                    if (keyValuePair.IsSetValue()) 
                                    {
                                        Console.WriteLine("                                Value");
                                        Console.WriteLine("                                    {0}", keyValuePair.Value);
                                    }
                                }
                            } 
                            if (savedForLaterItem.IsSetPrice()) 
                            {
                                Console.WriteLine("                        Price");
                                Price  price = savedForLaterItem.Price;
                                if (price.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", price.Amount);
                                }
                                if (price.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", price.CurrencyCode);
                                }
                                if (price.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", price.FormattedPrice);
                                }
                            } 
                            if (savedForLaterItem.IsSetItemTotal()) 
                            {
                                Console.WriteLine("                        ItemTotal");
                                Price  itemTotal = savedForLaterItem.ItemTotal;
                                if (itemTotal.IsSetAmount()) 
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", itemTotal.Amount);
                                }
                                if (itemTotal.IsSetCurrencyCode()) 
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", itemTotal.CurrencyCode);
                                }
                                if (itemTotal.IsSetFormattedPrice()) 
                                {
                                    Console.WriteLine("                            FormattedPrice");
                                    Console.WriteLine("                                {0}", itemTotal.FormattedPrice);
                                }
                            } 
                        }
                    } 
                    if (cart.IsSetSimilarProducts()) 
                    {
                        Console.WriteLine("                SimilarProducts");
                        SimilarProducts  similarProducts = cart.SimilarProducts;
                        List<SimilarProduct> similarProductList = similarProducts.SimilarProduct;
                        foreach (SimilarProduct similarProduct in similarProductList) 
                        {
                            Console.WriteLine("                    SimilarProduct");
                            if (similarProduct.IsSetASIN()) 
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", similarProduct.ASIN);
                            }
                            if (similarProduct.IsSetTitle()) 
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", similarProduct.Title);
                            }
                        }
                    } 
                    if (cart.IsSetTopSellers()) 
                    {
                        Console.WriteLine("                TopSellers");
                        TopSellers  topSellers = cart.TopSellers;
                        List<TopSeller> topSellerList = topSellers.TopSeller;
                        foreach (TopSeller topSeller in topSellerList) 
                        {
                            Console.WriteLine("                    TopSeller");
                            if (topSeller.IsSetASIN()) 
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", topSeller.ASIN);
                            }
                            if (topSeller.IsSetTitle()) 
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", topSeller.Title);
                            }
                        }
                    } 
                    if (cart.IsSetNewReleases()) 
                    {
                        Console.WriteLine("                NewReleases");
                        NewReleases  newReleases = cart.NewReleases;
                        List<NewRelease> newReleaseList = newReleases.NewRelease;
                        foreach (NewRelease newRelease in newReleaseList) 
                        {
                            Console.WriteLine("                    NewRelease");
                            if (newRelease.IsSetASIN()) 
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", newRelease.ASIN);
                            }
                            if (newRelease.IsSetTitle()) 
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", newRelease.Title);
                            }
                        }
                    } 
                    if (cart.IsSetSimilarViewedProducts()) 
                    {
                        Console.WriteLine("                SimilarViewedProducts");
                        SimilarViewedProducts  similarViewedProducts = cart.SimilarViewedProducts;
                        List<SimilarViewedProduct> similarViewedProductList = similarViewedProducts.SimilarViewedProduct;
                        foreach (SimilarViewedProduct similarViewedProduct in similarViewedProductList) 
                        {
                            Console.WriteLine("                    SimilarViewedProduct");
                            if (similarViewedProduct.IsSetASIN()) 
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", similarViewedProduct.ASIN);
                            }
                            if (similarViewedProduct.IsSetTitle()) 
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", similarViewedProduct.Title);
                            }
                        }
                    } 
                    if (cart.IsSetOtherCategoriesSimilarProducts()) 
                    {
                        Console.WriteLine("                OtherCategoriesSimilarProducts");
                        OtherCategoriesSimilarProducts  otherCategoriesSimilarProducts = cart.OtherCategoriesSimilarProducts;
                        List<OtherCategoriesSimilarProduct> otherCategoriesSimilarProductList = otherCategoriesSimilarProducts.OtherCategoriesSimilarProduct;
                        foreach (OtherCategoriesSimilarProduct otherCategoriesSimilarProduct in otherCategoriesSimilarProductList) 
                        {
                            Console.WriteLine("                    OtherCategoriesSimilarProduct");
                            if (otherCategoriesSimilarProduct.IsSetASIN()) 
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", otherCategoriesSimilarProduct.ASIN);
                            }
                            if (otherCategoriesSimilarProduct.IsSetTitle()) 
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", otherCategoriesSimilarProduct.Title);
                            }
                        }
                    } 
                }

            } 
            catch (AmazonECSException ex) 
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
            }
        }
                            }
}
